﻿/**
* @description  Class to test MP3 playback.
*/
package test {
	
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import com.moke.media.controllers.MP3Controller;
	import com.moke.media.displays.MP3Display;
	import com.moke.media.soundVisualizers.*;
	import com.moke.media.events.MediaEvent;
	
	[SWF(width=550, height=400)]

	public class MP3Test extends Sprite {

		private var _mp3Controller:MP3Controller;
		private var _mp3Display:MP3Display;
		
		/**
		* @description  Constructor.
		*/
		public function MP3Test() {
			init();
		}
		
		/**
		* @description  Creates controller and display, then loads video.
		*/
		private function init():void {
			_mp3Controller = new MP3Controller();
			_mp3Controller.addEventListener(Event.COMPLETE, mediaInit);
			_mp3Controller.addEventListener(MediaEvent.COMPLETE, mediaComplete);

			_mp3Display = new MP3Display();
			addChild(_mp3Display);
			_mp3Display.x = 115;
			_mp3Display.y = 80;
			_mp3Display.displayWidth = 320;
			_mp3Display.displayHeight = 240;
			_mp3Display.setController(_mp3Controller);
			
			var verticalBars:PulsingBase = new PulsingBase(_mp3Display.displayWidth, _mp3Display.displayHeight);
			verticalBars.FFTMode = false;
			MP3Display(_mp3Display).setVisualizer(verticalBars);

			_mp3Controller.loadMedia("../assets/Book Worm Theme.mp3");

			stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDown);
		}
		
		/**
		* @description  Event handler for when media starts.
		*
		* @param  pEvent  Event fired by MediaController.
		*/
		private function mediaInit(pEvent:Event):void {
			trace("MP3 init");
		}

		/**
		* @description  Event handler for when media completes.
		*
		* @param  pEvent  Event fired by MediaController.
		*/
		private function mediaComplete(pEvent:MediaEvent):void {
			trace("MP3 complete");
		}

		/**
		* @description  Event handler for when stage is clicked.
		*
		* @param  pEvent  Event fired by Mouse.
		*/
		private function mouseDown(pEvent:MouseEvent):void {
			_mp3Controller.pauseMedia(!_mp3Controller.paused);
		}

	}
	
}